package com.example.system.controller;

import com.example.core.controller.BaseController;
import com.example.core.domain.R;
import com.example.core.domain.TableDataInfo;
import com.example.system.domain.question.dto.QuestionAddDTO;
import com.example.system.domain.question.dto.QuestionEditDTO;
import com.example.system.domain.question.dto.QuestionQueryDTO;
import com.example.system.domain.question.vo.QuestionDetailVO;
import com.example.system.service.IQuestionService;
import com.example.system.service.impl.QuestionServiceImpl;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
@Tag(name="题目管理接口")
public class QuestionController extends BaseController {
    @Autowired
    private QuestionServiceImpl questionService;

    @GetMapping("/list")
    public TableDataInfo list( QuestionQueryDTO questionQueryDTO) {
        return getDataTable(questionService.list(questionQueryDTO));
    }

    @PostMapping("/add")
    public R<Void> add(@RequestBody QuestionAddDTO questionAddDto){
        boolean rows = questionService.add(questionAddDto);
        return toResult(rows);
    }

    @GetMapping("/detail")
    public R<QuestionDetailVO> detail(Long questionId){
        QuestionDetailVO questionDetailVO = questionService.detaail(questionId);
        return R.ok(questionDetailVO);
    }

    @PutMapping("/edit")
    public R<Void> update(@RequestBody QuestionEditDTO questionEditDTO){
        return toResult( questionService.edit(questionEditDTO));
    }


    @DeleteMapping("/delete")
    public R<Void> delete(Long questionId){
      return toResult(questionService.delete(questionId));
    }

}
